package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysType;
import com.ruoyi.project.system.service.ISysTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(description = "搜索服务")
@RestController
@RequestMapping("/mobileUser/search/")
public class UserSearchController {

    @Autowired
    private ISysTypeService sysTypeService;


    // 搜索服务类型——> 根据名称
    @SignatureValidation
    @ApiOperation("搜索服务类型")
    @GetMapping("/getList/{typeName}")
    public AjaxResult queryType(@PathVariable("typeName") String typeName) {
        SysType sysType = new SysType();
        sysType.setTypeName(typeName);
        List<SysType> list = new ArrayList<>();
        List<SysType> typeList = sysTypeService.queryAllType(sysType);
        for (int i = 0; i < typeList.size(); i++) {
            try {
                String ancestors = typeList.get(i).getAncestors();
                String[] split = ancestors.split(",");
                if (split[1] != null) {
                    list.add(typeList.get(i));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return AjaxResult.success(list);
    }
}
